package com.examsystem.dao;


import com.examsystem.pojo.Score;
import com.examsystem.pojo.vo.ScoreVo;
import com.examsystem.pojo.vo.StudentScore;
import org.apache.ibatis.annotations.*;

import java.util.List;
/**
 * @author fire'ge
 */
@Mapper
public interface ScoreMapper {

    /*
    学生端
     */

    /**添加一个Score
     * @param score 传入score类
     * @return int
     */
    int addScore(Score score);
    /**根据id删除一个Score
     * @param id 传入id
     * @return int
     */
    int deleteScoreById(int id);

    /**更新Score
     * @param score 传入score类
     * @return int
     */
    int updateScore(Score score);
    /**根据id查询,返回一个Score
     * @param id 传入id
     * @return int
     */
    Score queryScoreById(int id);
    /**查询全部Score,返回list集合
     * @return List<Score>
     */
    List<Score> queryAllScore();

    /**
     * @param userId 用户id
     * @return list集合的学生成绩对象
     */
    List<StudentScore> queryScoresByUserId(int userId);




    /*
      教师端
     */

    /**
     * 查看本班级的学生成绩情况【这里暂时考虑一个教师只教一个班】
     * @param classId  班级id
     * @param paperId 试卷id
     * @return  各个学生的成绩情况【按照成绩从高到低】
     */
    @Select("select * from markS  where studentPaper = #{paperId} and classId= #{classId}  order by studentScore desc")
    @Results({
            @Result(column = "studentId",property = "studentId"),
            @Result(column = "studentName",property = "studentName"),
            @Result(column = "studentClass",property = "studentClass"),
            @Result(column = "classId",property = "classId"),
            @Result(column = "studentScore",property = "studentScore"),
            @Result(column = "studentPaper",property = "studentPaper")
    })
    List<ScoreVo> studentScore(@Param("classId") int classId,@Param("paperId") int paperId);




    /**
     * 参加此次考试的所有班级的成绩情况【以平均分为标准】
     * @param paperId  试卷id
     * @return  list集合的成绩对象
     */
    @Select("select  round(avg(studentScore),4) as averageMark,ms.studentClass,ms.classId,ms.studentPaper\n" +
            "from markS ms where ms.studentPaper=1 group by ms.classId;")
    @Results({
            @Result(column = "averageMark",property = "averageMark"),
            @Result(column = "studentClass",property = "studentClass"),
            @Result(column = "classId",property = "classId"),
            @Result(column = "studentPaper",property = "studentPaper")
    })
    List<ScoreVo> classScore(@Param("paperId") int paperId);






    /**
     * 查找参加了这次考试的所有班级
     * @param paperId  试卷id
     * @return list集合的班级id
     */
    @Select("select classId from exam.student_score where studentPaperId= #{paperId}")
    List<Integer> partOrNotIds(int paperId);

}
